package rule;

import model.Board;
import model.Position;

/**
 * Created by qianyu.zm on 2017/3/7.
 */
public class KalilonRuleOperator implements RuleOperator{

    @Override
    public void execute(Board board, Position operatePosition) {
        int x = operatePosition.x;
        int y = operatePosition.y;
        int operateNumOtherLine = x == 0 ? 3 : 7 << x - 1;
        int operateNumCurrentLine = x == 0 ? 2 : 5 << x - 1;
        if(y > 0){
            board.table[y - 1] ^= operateNumOtherLine;
        }
        board.table[y] ^= operateNumCurrentLine;
        if(y < board.longerSide - 1){
            board.table[y + 1] ^= operateNumOtherLine;
        }
    }

    private int[] defineOperateScope(int index, int max){
        int size = (index > 0 && index < max - 1) ? 3 : 2;
        int[] operate = new int[size];
        if(index > 0){
            operate[0] = index - 1;
            operate[1] = index;
        }
        if(index < max - 1){
            operate[operate.length - 1] = index + 1;
            operate[operate.length - 2] = index;
        }
        return operate;
    }
}
